﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Web;

namespace TomNet.IMSC.Web.Common
{
    public static class ExtMethod
    {
        /// <summary>
        /// 遍历对象将null改为""
        /// </summary>
        public static void HandleModelValue<T>(T model)
        {
            Type type = model.GetType();

            PropertyInfo[] ps = type.GetProperties();
            foreach (PropertyInfo p in ps)
            {
                object res = p.GetValue(model, null);
                if (res == null)
                {
                    p.SetValue(model, "", null);
                }
            }
        }

        /// <summary>
        /// 遍历对象将null改为""
        /// </summary>
        public static void HandleListValue<T>(List<T> list)
        {
            for (int i = 0; i < list.Count; i++)
            {
                HandleModelValue(list[i]);
            }


        }

    }
}